package com.itheima.tanhua.service;

import com.itheima.tanhua.api.UserLocationApi;
import com.itheima.tanhua.dto.LocationDto;
import com.itheima.tanhua.exception.BusinessException;
import com.itheima.tanhua.utils.UserHolder;
import com.itheima.tanhua.vo.ErrorResult;
import org.apache.dubbo.config.annotation.DubboReference;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.stereotype.Service;

/**
 * @author Lff
 * @date 2022/4/1
 */
@Service
public class BaiduService {

    @DubboReference
    private UserLocationApi userLocationApi;

    /**
     * 保存地理位置
     *
     * @param locationDto
     */
    public void uploadLocation(LocationDto locationDto) {
        //设置当前用户id
        locationDto.setUserId(UserHolder.getUser().getId());
        //调用api进行保存
        Boolean flag = userLocationApi.updateLocation(locationDto);
        if (!flag) {
            throw new BusinessException(ErrorResult.error());
        }
    }
}
